#include "Miner.hpp"

#include "../FSM/MinerStates.hpp"

Miner::Miner() :
    smeg::core::BaseObject(),
    m_pStateMachine( NULL ),
    m_pWife( NULL ),
    m_iThirst(0),
    m_iFatigue(0),
    m_iGoldInPocket(0),
    m_iWealth(0)
{
    m_pStateMachine = new smeg::core::StateMachine< Miner >( this );
    m_pStateMachine->ChangeState( EnterMineAndDigForNugget::GetInstance() );
}

Miner::~Miner() {
    delete m_pStateMachine;
    m_pStateMachine = NULL;
}

void Miner::Update( float _fDeltaTime ) {
    m_pStateMachine->Update();
}

bool Miner::HandleMessage( const smeg::core::MessageInfo& _Msg ) {
    return m_pStateMachine->HandleMessage( _Msg );
}

smeg::core::StateMachine< Miner >* Miner::GetStateMachine() {
    return m_pStateMachine;
}

void Miner::SetWife( smeg::core::BaseObject* _pWife ) {
    m_pWife = _pWife;
}

smeg::core::BaseObject* Miner::GetWife() const {
    return m_pWife;
}

bool Miner::IsThirsty() const {
    return m_iThirst > THIRST_MAX;
}

void Miner::BuyAndDrinkAWhiskey() {
    m_iThirst = 0;
    m_iWealth -= 2;

    if ( m_iWealth < 0 ) {
        m_iWealth = 0;
    }
}

void Miner::IncreaseThirst() {
    ++m_iThirst;
}


bool Miner::IsTired() const {
    return m_iFatigue > 0;
}

void Miner::DecreaseFatigue() {
    --m_iFatigue;
}

void Miner::IncreaseFatigue() {
    ++m_iFatigue;
}


bool Miner::ArePocketFull() const {
    return m_iGoldInPocket > POCKET_MAX;
}

int Miner::GetGoldCarried() const {
    return m_iGoldInPocket;
}

void Miner::SetGoldCarried( int _iGold ) {
    m_iGoldInPocket = _iGold;
}

void Miner::AddGoldCarried( int _iGold ) {
    m_iGoldInPocket += _iGold;
}


bool Miner::IsWealthy() const {
    return m_iWealth > WEALTH_MIN;
}

int Miner::GetWealth() const {
    return m_iWealth;
}

void Miner::AddGoldToWealth( int _iGold ) {
    m_iWealth += _iGold;
}
